{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 对数几率回归"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 考虑二分类问题，对于二分类问题只有0和1，因此需要将结果映射为0和1即可，常用的函数为sigmoid函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn.datasets import load_iris,make_classification\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "sigmoid = lambda x:1./(1+np.exp(-x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x113ae8438>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH1lJREFUeJzt3Wl4XOWZ5vH/o9JieRW2vMo2XrAxBtsYhFkGCAmLjUkw\nMJA2maTJQhOmA00ymSTQPZPOND3TSegkE9IEj1kCnQk4EGhwiMEmNAQIq/CKDLblVZIlWd4ta696\n+kOVTSEkqyxX6VSV7t91lavOOW/VeXRKdfvVW2cxd0dERLJLTtAFiIhI8incRUSykMJdRCQLKdxF\nRLKQwl1EJAsp3EVEspDCXUQkCyncRUSykMJdRCQL5Qa14uLiYp8wYUJQqxcRyUjvvffebncf3l27\nwMJ9woQJlJWVBbV6EZGMZGbbE2mnYRkRkSykcBcRyUIKdxGRLKRwFxHJQgp3EZEs1G24m9nDZrbL\nzN7vYrmZ2b1mVmFma83srOSXKSIixyORnvsjwLxjLL8SmBK73QLcf+JliYjIieh2P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M/sw9j98jx2rLuB+4G6iH8S7iQ4Z\nffVE1peMuo5sLzP7O6Ad+E0XL5P07ZVpzGwg8BTwTXc/2GHxSmC8uzfEvk95BpjSS6Wl7Xtj0cuA\nXg3c1cniILfZUSeSRccr0HB398t68LSELsYN1JnZaHevif1ZuCsVNZpZLnAdcPYxXqM6dr/LzP6N\n6J9gJ/SBSHTbmdkDwHOdLEp0Oya1LjP7MvBZ4FKPDTZ28hpJ316dSNqF35PNzPKIBvtv3P3pjsvj\nw97dl5nZL82s2N1Tfg6VBN6bQLZZzJXASnev67ggyG1GYlmU9O2WicMyS4GFZlZgZhOJ/u/7Thft\nboo9vglI2l8CHVwGfOjuVZ0tNLMBZjboyGOiXyq+31nbZOkwxnltF+tL5MLnya5rHvBd4Gp3b+yi\nTW9tr7S88Hvs+5uHgA/c/addtBkVa4eZzSH6Od6Tyrpi60rkven1bRany7+gg9pmMYlkUfI/j6n+\n9rinN6KhVAW0AHXA8rhlf0f0m+UNwJVx8x8ktmcNMAx4CdgE/BEYmqI6HwFu7TBvDLAs9ngS0W++\n1wDlRIcnUr3tfg2sA9bGfkFGd6wrNj2f6N4Ym3uprgqi44qrY7dFQW6vzn5+4NYj7yfRPT7uiy1f\nR9xeWyms6UKiw2lr47bT/A513RbbNmuIfjF9QarrOtZ7E/Q2i613ANGwHhI3r9e3GdH/XGqAtlh+\nfa2rLEr151FHqIqIZKFMHJYREZFuKNxFRLKQwl1EJAsp3EVEspDCXUQkCyncRUSykMJdRCQLKdxF\nRLLQfwAQyl4UsTc3ggAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x113be8eb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.linspace(-10,10,10000)\n",
    "y = sigmoid(x)\n",
    "plt.plot(x,y)\n",
    "plt.scatter(0,sigmoid(0))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 上述就是sigmoid函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data = load_iris()\n",
    "X = data.data[data.target != 0]\n",
    "y = data.target[data.target != 0]\n",
    "y[y == 1] = 0\n",
    "y[y == 2] = 1\n",
    "Y = y.reshape(-1,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[ 7. ,  3.2,  4.7,  1.4],\n",
       "        [ 6.4,  3.2,  4.5,  1.5],\n",
       "        [ 6.9,  3.1,  4.9,  1.5],\n",
       "        [ 5.5,  2.3,  4. ,  1.3],\n",
       "        [ 6.5,  2.8,  4.6,  1.5]]), array([[0],\n",
       "        [0],\n",
       "        [0],\n",
       "        [0],\n",
       "        [0]]))"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:5],Y[:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 定义对数几率回归的梯度下降解法\n",
    "\n",
    "* 根据西瓜书中的说法，逻辑回归是不怎么准确的，应该使用对数几率回归，简称对数回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class LogisticRegression(object):\n",
    "    def __init__(self):\n",
    "        self.sigmoid = lambda x:1./(1+np.exp(-x))\n",
    "    def fit(self, X, y):\n",
    "        self.w = np.random.randn(X.shape[1],1)\n",
    "        for _ in range(1000):\n",
    "            y_pred = self.sigmoid(X @ self.w)\n",
    "            self.w -= 0.01 * X.T @ (y_pred - y) #梯度下降\n",
    "            print(np.mean(0.5*(y_pred- y)**2))\n",
    "    def predict(self,X):\n",
    "        y_pred = np.round(self.sigmoid(X.dot(self.w)))\n",
    "        return y_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "lr = LogisticRegression()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.249985443981\n",
      "0.249999999846\n",
      "0.249999874152\n",
      "0.249999943556\n",
      "0.249999998665\n",
      "0.249973057264\n",
      "0.249999999984\n",
      "0.233347132686\n",
      "0.249999999999\n",
      "0.0654220716453\n",
      "0.133225655915\n",
      "0.249999992943\n",
      "0.24998527144\n",
      "0.249999999914\n",
      "0.240764465846\n",
      "0.249999999998\n",
      "0.0431293437346\n",
      "0.0669511869457\n",
      "0.249947396729\n",
      "0.24999999872\n",
      "0.249999454103\n",
      "0.249999531607\n",
      "0.249999993498\n",
      "0.249754778418\n",
      "0.249999999915\n",
      "0.160315393172\n",
      "0.249999998654\n",
      "0.243591993724\n",
      "0.249999999973\n",
      "0.0413836905634\n",
      "0.243283931434\n",
      "0.249999999887\n",
      "0.249945994128\n",
      "0.249999964302\n",
      "0.249999369723\n",
      "0.249984269241\n",
      "0.24999999198\n",
      "0.239747083555\n",
      "0.249999999792\n",
      "0.056678605032\n",
      "0.248276879162\n",
      "0.249999995238\n",
      "0.24998083317\n",
      "0.249998150435\n",
      "0.249999760717\n",
      "0.248803360436\n",
      "0.249999996606\n",
      "0.128892141852\n",
      "0.249998070801\n",
      "0.249770547695\n",
      "0.24999997449\n",
      "0.191353395226\n",
      "0.249999967208\n",
      "0.185075162935\n",
      "0.249999924872\n",
      "0.202006995375\n",
      "0.24999995868\n",
      "0.159714038936\n",
      "0.249998863741\n",
      "0.240356823023\n",
      "0.249999970702\n",
      "0.107651307362\n",
      "0.249663579103\n",
      "0.24998438073\n",
      "0.249995697147\n",
      "0.239735551013\n",
      "0.249999882215\n",
      "0.119817304141\n",
      "0.249628663612\n",
      "0.249905130052\n",
      "0.249995166\n",
      "0.222563541355\n",
      "0.249999416857\n",
      "0.138855643039\n",
      "0.249768651317\n",
      "0.24860402526\n",
      "0.249996693957\n",
      "0.174990255407\n",
      "0.249972207358\n",
      "0.222903823839\n",
      "0.249996516521\n",
      "0.147827740795\n",
      "0.249424194273\n",
      "0.244937523152\n",
      "0.249989189035\n",
      "0.159810172807\n",
      "0.249506135886\n",
      "0.236363944397\n",
      "0.249980216733\n",
      "0.153408788459\n",
      "0.248201068964\n",
      "0.239827622698\n",
      "0.249944943645\n",
      "0.160860687229\n",
      "0.247823631347\n",
      "0.233963662955\n",
      "0.249876564577\n",
      "0.161248005007\n",
      "0.245959775843\n",
      "0.232431460645\n",
      "0.249701788315\n",
      "0.16410132856\n",
      "0.24415041981\n",
      "0.228816683796\n",
      "0.249320392649\n",
      "0.165518645472\n",
      "0.241896584516\n",
      "0.225409159803\n",
      "0.248503843624\n",
      "0.166747863067\n",
      "0.239900313153\n",
      "0.221547394025\n",
      "0.246945039692\n",
      "0.167439940887\n",
      "0.238098991618\n",
      "0.21790033604\n",
      "0.244567484804\n",
      "0.167032131359\n",
      "0.235759752952\n",
      "0.215148936147\n",
      "0.241997122451\n",
      "0.165236475745\n",
      "0.23170219027\n",
      "0.212805254174\n",
      "0.239969995363\n",
      "0.163292699308\n",
      "0.225375751733\n",
      "0.208155174376\n",
      "0.238206362338\n",
      "0.163775756945\n",
      "0.218874129404\n",
      "0.198654816864\n",
      "0.234955234102\n",
      "0.168913589348\n",
      "0.216531221262\n",
      "0.185641055809\n",
      "0.226603032958\n",
      "0.174030137611\n",
      "0.213887692675\n",
      "0.171874410712\n",
      "0.20709059614\n",
      "0.163724641014\n",
      "0.191485674429\n",
      "0.149393791087\n",
      "0.166869884422\n",
      "0.125201480729\n",
      "0.129546116031\n",
      "0.0796677798557\n",
      "0.0633951709635\n",
      "0.0378561770664\n",
      "0.0242207735145\n",
      "0.0207596965382\n",
      "0.0168062786792\n",
      "0.0197621476608\n",
      "0.0162631485464\n",
      "0.0193843386616\n",
      "0.016053294226\n",
      "0.0192100509148\n",
      "0.0159554303587\n",
      "0.0191213729484\n",
      "0.0159050630274\n",
      "0.0190726426631\n",
      "0.0158769379225\n",
      "0.0190435067416\n",
      "0.0158597422185\n",
      "0.0190242333743\n",
      "0.0158480536436\n",
      "0.0190099966028\n",
      "0.0158391799031\n",
      "0.0189983560476\n",
      "0.0158317585888\n",
      "0.0189880641354\n",
      "0.0158250929053\n",
      "0.0189784789451\n",
      "0.0158188242252\n",
      "0.0189692688066\n",
      "0.0158127672187\n",
      "0.0189602618429\n",
      "0.0158068258372\n",
      "0.0189513687785\n",
      "0.0158009501947\n",
      "0.0189425431527\n",
      "0.0157951143375\n",
      "0.0189337607471\n",
      "0.0157893047469\n",
      "0.0189250089207\n",
      "0.0157835143783\n",
      "0.0189162810699\n",
      "0.0157777395634\n",
      "0.0189075737454\n",
      "0.0157719783983\n",
      "0.0188988851478\n",
      "0.0157662299025\n",
      "0.0188902143431\n",
      "0.0157604935794\n",
      "0.018881560851\n",
      "0.0157547691864\n",
      "0.0188729244301\n",
      "0.0157490566149\n",
      "0.0188643049643\n",
      "0.0157433558261\n",
      "0.0188557024036\n",
      "0.0157376668186\n",
      "0.0188471167328\n",
      "0.0157319896103\n",
      "0.0188385479548\n",
      "0.0157263242292\n",
      "0.018829996082\n",
      "0.0157206707087\n",
      "0.0188214611314\n",
      "0.0157150290849\n",
      "0.0188129431225\n",
      "0.015709399395\n",
      "0.018804442076\n",
      "0.0157037816772\n",
      "0.0187959580127\n",
      "0.0156981759696\n",
      "0.0187874909536\n",
      "0.0156925823103\n",
      "0.0187790409194\n",
      "0.0156870007374\n",
      "0.0187706079305\n",
      "0.0156814312886\n",
      "0.018762192007\n",
      "0.0156758740015\n",
      "0.0187537931686\n",
      "0.0156703289136\n",
      "0.0187454114348\n",
      "0.015664796062\n",
      "0.0187370468243\n",
      "0.0156592754835\n",
      "0.0187286993558\n",
      "0.0156537672146\n",
      "0.0187203690475\n",
      "0.0156482712918\n",
      "0.0187120559172\n",
      "0.0156427877511\n",
      "0.0187037599822\n",
      "0.0156373166282\n",
      "0.0186954812596\n",
      "0.0156318579587\n",
      "0.0186872197662\n",
      "0.0156264117778\n",
      "0.0186789755181\n",
      "0.0156209781204\n",
      "0.0186707485314\n",
      "0.0156155570213\n",
      "0.0186625388216\n",
      "0.0156101485149\n",
      "0.018654346404\n",
      "0.0156047526352\n",
      "0.0186461712935\n",
      "0.0155993694161\n",
      "0.0186380135045\n",
      "0.0155939988913\n",
      "0.0186298730514\n",
      "0.0155886410938\n",
      "0.018621749948\n",
      "0.0155832960568\n",
      "0.0186136442077\n",
      "0.0155779638129\n",
      "0.0186055558439\n",
      "0.0155726443946\n",
      "0.0185974848694\n",
      "0.0155673378339\n",
      "0.0185894312967\n",
      "0.0155620441628\n",
      "0.0185813951381\n",
      "0.0155567634126\n",
      "0.0185733764056\n",
      "0.0155514956148\n",
      "0.0185653751107\n",
      "0.0155462408002\n",
      "0.0185573912648\n",
      "0.0155409989995\n",
      "0.0185494248789\n",
      "0.015535770243\n",
      "0.0185414759637\n",
      "0.0155305545609\n",
      "0.0185335445297\n",
      "0.0155253519829\n",
      "0.0185256305869\n",
      "0.0155201625384\n",
      "0.0185177341453\n",
      "0.0155149862567\n",
      "0.0185098552144\n",
      "0.0155098231665\n",
      "0.0185019938034\n",
      "0.0155046732965\n",
      "0.0184941499215\n",
      "0.0154995366749\n",
      "0.0184863235773\n",
      "0.0154944133297\n",
      "0.0184785147793\n",
      "0.0154893032885\n",
      "0.0184707235357\n",
      "0.0154842065787\n",
      "0.0184629498545\n",
      "0.0154791232273\n",
      "0.0184551937433\n",
      "0.0154740532611\n",
      "0.0184474552096\n",
      "0.0154689967065\n",
      "0.0184397342606\n",
      "0.0154639535896\n",
      "0.0184320309031\n",
      "0.0154589239362\n",
      "0.0184243451439\n",
      "0.0154539077719\n",
      "0.0184166769894\n",
      "0.0154489051219\n",
      "0.0184090264458\n",
      "0.0154439160109\n",
      "0.0184013935191\n",
      "0.0154389404637\n",
      "0.018393778215\n",
      "0.0154339785044\n",
      "0.018386180539\n",
      "0.0154290301571\n",
      "0.0183786004964\n",
      "0.0154240954454\n",
      "0.0183710380922\n",
      "0.0154191743925\n",
      "0.0183634933313\n",
      "0.0154142670216\n",
      "0.0183559662183\n",
      "0.0154093733554\n",
      "0.0183484567575\n",
      "0.0154044934162\n",
      "0.0183409649531\n",
      "0.015399627226\n",
      "0.0183334908092\n",
      "0.0153947748068\n",
      "0.0183260343294\n",
      "0.0153899361799\n",
      "0.0183185955174\n",
      "0.0153851113665\n",
      "0.0183111743765\n",
      "0.0153803003874\n",
      "0.0183037709099\n",
      "0.0153755032631\n",
      "0.0182963851205\n",
      "0.0153707200138\n",
      "0.018289017011\n",
      "0.0153659506595\n",
      "0.0182816665842\n",
      "0.0153611952196\n",
      "0.0182743338423\n",
      "0.0153564537134\n",
      "0.0182670187875\n",
      "0.0153517261598\n",
      "0.0182597214219\n",
      "0.0153470125776\n",
      "0.0182524417474\n",
      "0.0153423129849\n",
      "0.0182451797655\n",
      "0.0153376273998\n",
      "0.0182379354777\n",
      "0.01533295584\n",
      "0.0182307088854\n",
      "0.0153282983228\n",
      "0.0182234999897\n",
      "0.0153236548653\n",
      "0.0182163087916\n",
      "0.0153190254841\n",
      "0.0182091352918\n",
      "0.0153144101958\n",
      "0.018201979491\n",
      "0.0153098090165\n",
      "0.0181948413896\n",
      "0.0153052219619\n",
      "0.018187720988\n",
      "0.0153006490474\n",
      "0.0181806182863\n",
      "0.0152960902884\n",
      "0.0181735332845\n",
      "0.0152915456996\n",
      "0.0181664659824\n",
      "0.0152870152955\n",
      "0.0181594163798\n",
      "0.0152824990904\n",
      "0.0181523844761\n",
      "0.0152779970982\n",
      "0.0181453702708\n",
      "0.0152735093325\n",
      "0.0181383737631\n",
      "0.0152690358066\n",
      "0.018131394952\n",
      "0.0152645765334\n",
      "0.0181244338366\n",
      "0.0152601315256\n",
      "0.0181174904156\n",
      "0.0152557007957\n",
      "0.0181105646877\n",
      "0.0152512843555\n",
      "0.0181036566515\n",
      "0.0152468822169\n",
      "0.0180967663053\n",
      "0.0152424943912\n",
      "0.0180898936475\n",
      "0.0152381208897\n",
      "0.0180830386761\n",
      "0.015233761723\n",
      "0.0180762013891\n",
      "0.0152294169018\n",
      "0.0180693817845\n",
      "0.0152250864361\n",
      "0.01806257986\n",
      "0.0152207703359\n",
      "0.0180557956132\n",
      "0.0152164686107\n",
      "0.0180490290416\n",
      "0.0152121812698\n",
      "0.0180422801426\n",
      "0.0152079083222\n",
      "0.0180355489135\n",
      "0.0152036497765\n",
      "0.0180288353513\n",
      "0.0151994056411\n",
      "0.0180221394532\n",
      "0.015195175924\n",
      "0.018015461216\n",
      "0.015190960633\n",
      "0.0180088006364\n",
      "0.0151867597756\n",
      "0.0180021577113\n",
      "0.0151825733588\n",
      "0.0179955324372\n",
      "0.0151784013896\n",
      "0.0179889248105\n",
      "0.0151742438744\n",
      "0.0179823348276\n",
      "0.0151701008196\n",
      "0.0179757624847\n",
      "0.015165972231\n",
      "0.017969207778\n",
      "0.0151618581143\n",
      "0.0179626707034\n",
      "0.0151577584749\n",
      "0.017956151257\n",
      "0.0151536733178\n",
      "0.0179496494346\n",
      "0.0151496026477\n",
      "0.0179431652318\n",
      "0.0151455464693\n",
      "0.0179366986444\n",
      "0.0151415047865\n",
      "0.0179302496678\n",
      "0.0151374776033\n",
      "0.0179238182975\n",
      "0.0151334649233\n",
      "0.0179174045289\n",
      "0.0151294667497\n",
      "0.0179110083571\n",
      "0.0151254830857\n",
      "0.0179046297773\n",
      "0.0151215139338\n",
      "0.0178982687846\n",
      "0.0151175592966\n",
      "0.017891925374\n",
      "0.0151136191761\n",
      "0.0178855995403\n",
      "0.0151096935743\n",
      "0.0178792912783\n",
      "0.0151057824926\n",
      "0.0178730005828\n",
      "0.0151018859324\n",
      "0.0178667274482\n",
      "0.0150980038947\n",
      "0.0178604718692\n",
      "0.0150941363801\n",
      "0.0178542338403\n",
      "0.0150902833892\n",
      "0.0178480133557\n",
      "0.0150864449221\n",
      "0.0178418104097\n",
      "0.0150826209786\n",
      "0.0178356249965\n",
      "0.0150788115583\n",
      "0.0178294571103\n",
      "0.0150750166606\n",
      "0.0178233067451\n",
      "0.0150712362845\n",
      "0.0178171738948\n",
      "0.0150674704289\n",
      "0.0178110585533\n",
      "0.015063719092\n",
      "0.0178049607144\n",
      "0.0150599822723\n",
      "0.0177988803719\n",
      "0.0150562599676\n",
      "0.0177928175193\n",
      "0.0150525521756\n",
      "0.0177867721502\n",
      "0.0150488588938\n",
      "0.0177807442582\n",
      "0.0150451801192\n",
      "0.0177747338366\n",
      "0.0150415158488\n",
      "0.0177687408788\n",
      "0.0150378660791\n",
      "0.017762765378\n",
      "0.0150342308064\n",
      "0.0177568073276\n",
      "0.015030610027\n",
      "0.0177508667205\n",
      "0.0150270037365\n",
      "0.0177449435499\n",
      "0.0150234119305\n",
      "0.0177390378088\n",
      "0.0150198346044\n",
      "0.0177331494901\n",
      "0.0150162717531\n",
      "0.0177272785866\n",
      "0.0150127233714\n",
      "0.0177214250912\n",
      "0.0150091894538\n",
      "0.0177155889965\n",
      "0.0150056699947\n",
      "0.0177097702952\n",
      "0.015002164988\n",
      "0.0177039689799\n",
      "0.0149986744274\n",
      "0.0176981850432\n",
      "0.0149951983065\n",
      "0.0176924184775\n",
      "0.0149917366186\n",
      "0.0176866692752\n",
      "0.0149882893565\n",
      "0.0176809374286\n",
      "0.0149848565132\n",
      "0.01767522293\n",
      "0.014981438081\n",
      "0.0176695257716\n",
      "0.0149780340523\n",
      "0.0176638459455\n",
      "0.0149746444191\n",
      "0.017658183444\n",
      "0.0149712691731\n",
      "0.0176525382589\n",
      "0.0149679083059\n",
      "0.0176469103822\n",
      "0.0149645618088\n",
      "0.0176412998059\n",
      "0.0149612296728\n",
      "0.0176357065218\n",
      "0.0149579118888\n",
      "0.0176301305217\n",
      "0.0149546084474\n",
      "0.0176245717973\n",
      "0.0149513193388\n",
      "0.0176190303402\n",
      "0.0149480445533\n",
      "0.0176135061422\n",
      "0.0149447840806\n",
      "0.0176079991948\n",
      "0.0149415379106\n",
      "0.0176025094894\n",
      "0.0149383060324\n",
      "0.0175970370175\n",
      "0.0149350884355\n",
      "0.0175915817706\n",
      "0.0149318851087\n",
      "0.0175861437398\n",
      "0.0149286960408\n",
      "0.0175807229166\n",
      "0.0149255212203\n",
      "0.0175753192922\n",
      "0.0149223606355\n",
      "0.0175699328576\n",
      "0.0149192142745\n",
      "0.017564563604\n",
      "0.0149160821252\n",
      "0.0175592115226\n",
      "0.0149129641751\n",
      "0.0175538766042\n",
      "0.0149098604117\n",
      "0.0175485588399\n",
      "0.0149067708223\n",
      "0.0175432582205\n",
      "0.0149036953938\n",
      "0.017537974737\n",
      "0.014900634113\n",
      "0.01753270838\n",
      "0.0148975869664\n",
      "0.0175274591404\n",
      "0.0148945539405\n",
      "0.0175222270088\n",
      "0.0148915350214\n",
      "0.0175170119759\n",
      "0.014888530195\n",
      "0.0175118140323\n",
      "0.0148855394471\n",
      "0.0175066331685\n",
      "0.0148825627632\n",
      "0.0175014693749\n",
      "0.0148796001286\n",
      "0.0174963226422\n",
      "0.0148766515286\n",
      "0.0174911929605\n",
      "0.0148737169479\n",
      "0.0174860803203\n",
      "0.0148707963715\n",
      "0.0174809847119\n",
      "0.0148678897837\n",
      "0.0174759061255\n",
      "0.014864997169\n",
      "0.0174708445513\n",
      "0.0148621185115\n",
      "0.0174657999794\n",
      "0.0148592537951\n",
      "0.0174607723999\n",
      "0.0148564030037\n",
      "0.0174557618029\n",
      "0.0148535661208\n",
      "0.0174507681783\n",
      "0.0148507431298\n",
      "0.0174457915162\n",
      "0.0148479340139\n",
      "0.0174408318063\n",
      "0.0148451387562\n",
      "0.0174358890386\n",
      "0.0148423573394\n",
      "0.0174309632029\n",
      "0.0148395897462\n",
      "0.0174260542889\n",
      "0.0148368359592\n",
      "0.0174211622863\n",
      "0.0148340959606\n",
      "0.0174162871847\n",
      "0.0148313697325\n",
      "0.0174114289739\n",
      "0.0148286572569\n",
      "0.0174065876433\n",
      "0.0148259585155\n",
      "0.0174017631824\n",
      "0.0148232734899\n",
      "0.0173969555808\n",
      "0.0148206021616\n",
      "0.0173921648279\n",
      "0.0148179445118\n",
      "0.017387390913\n",
      "0.0148153005217\n",
      "0.0173826338255\n",
      "0.014812670172\n",
      "0.0173778935546\n",
      "0.0148100534437\n",
      "0.0173731700896\n",
      "0.0148074503172\n",
      "0.0173684634197\n",
      "0.014804860773\n",
      "0.017363773534\n",
      "0.0148022847913\n",
      "0.0173591004217\n",
      "0.0147997223523\n",
      "0.0173544440717\n",
      "0.014797173436\n",
      "0.0173498044731\n",
      "0.014794638022\n",
      "0.0173451816148\n",
      "0.0147921160901\n",
      "0.0173405754858\n",
      "0.0147896076197\n",
      "0.017335986075\n",
      "0.0147871125902\n",
      "0.0173314133711\n",
      "0.0147846309807\n",
      "0.0173268573629\n",
      "0.0147821627702\n",
      "0.0173223180391\n",
      "0.0147797079378\n",
      "0.0173177953886\n",
      "0.014777266462\n",
      "0.0173132893998\n",
      "0.0147748383214\n",
      "0.0173088000614\n",
      "0.0147724234946\n",
      "0.0173043273619\n",
      "0.0147700219598\n",
      "0.0172998712899\n",
      "0.0147676336953\n",
      "0.0172954318338\n",
      "0.0147652586789\n",
      "0.017291008982\n",
      "0.0147628968886\n",
      "0.0172866027229\n",
      "0.0147605483022\n",
      "0.0172822130448\n",
      "0.0147582128973\n",
      "0.0172778399361\n",
      "0.0147558906513\n",
      "0.0172734833848\n",
      "0.0147535815417\n",
      "0.0172691433793\n",
      "0.0147512855456\n",
      "0.0172648199076\n",
      "0.0147490026401\n",
      "0.017260512958\n",
      "0.0147467328022\n",
      "0.0172562225183\n",
      "0.0147444760087\n",
      "0.0172519485767\n",
      "0.0147422322364\n",
      "0.0172476911211\n",
      "0.0147400014619\n",
      "0.0172434501394\n",
      "0.0147377836615\n",
      "0.0172392256195\n",
      "0.0147355788118\n",
      "0.0172350175493\n",
      "0.0147333868888\n",
      "0.0172308259165\n",
      "0.0147312078687\n",
      "0.0172266507089\n",
      "0.0147290417276\n",
      "0.0172224919141\n",
      "0.0147268884413\n",
      "0.0172183495198\n",
      "0.0147247479855\n",
      "0.0172142235137\n",
      "0.014722620336\n",
      "0.0172101138833\n",
      "0.0147205054682\n",
      "0.0172060206161\n",
      "0.0147184033577\n",
      "0.0172019436996\n",
      "0.0147163139797\n",
      "0.0171978831212\n",
      "0.0147142373095\n",
      "0.0171938388683\n",
      "0.0147121733222\n",
      "0.0171898109283\n",
      "0.0147101219929\n",
      "0.0171857992884\n",
      "0.0147080832964\n",
      "0.0171818039359\n",
      "0.0147060572076\n",
      "0.0171778248581\n",
      "0.0147040437012\n",
      "0.017173862042\n",
      "0.0147020427518\n",
      "0.0171699154748\n",
      "0.0147000543339\n",
      "0.0171659851436\n",
      "0.014698078422\n",
      "0.0171620710354\n",
      "0.0146961149904\n",
      "0.0171581731372\n",
      "0.0146941640134\n",
      "0.0171542914359\n",
      "0.0146922254651\n",
      "0.0171504259184\n",
      "0.0146902993196\n",
      "0.0171465765716\n",
      "0.0146883855508\n",
      "0.0171427433823\n",
      "0.0146864841327\n",
      "0.0171389263373\n",
      "0.014684595039\n",
      "0.0171351254232\n",
      "0.0146827182436\n",
      "0.0171313406268\n",
      "0.0146808537199\n",
      "0.0171275719346\n",
      "0.0146790014417\n",
      "0.0171238193333\n",
      "0.0146771613823\n",
      "0.0171200828094\n",
      "0.0146753335152\n",
      "0.0171163623494\n",
      "0.0146735178137\n",
      "0.0171126579398\n",
      "0.014671714251\n",
      "0.0171089695669\n",
      "0.0146699228004\n",
      "0.0171052972171\n",
      "0.0146681434349\n",
      "0.0171016408768\n",
      "0.0146663761275\n",
      "0.0170980005322\n",
      "0.0146646208513\n",
      "0.0170943761695\n",
      "0.0146628775791\n",
      "0.017090767775\n",
      "0.0146611462837\n",
      "0.0170871753348\n",
      "0.0146594269379\n",
      "0.0170835988349\n",
      "0.0146577195143\n",
      "0.0170800382614\n",
      "0.0146560239857\n",
      "0.0170764936004\n",
      "0.0146543403246\n",
      "0.0170729648377\n",
      "0.0146526685034\n",
      "0.0170694519594\n",
      "0.0146510084947\n",
      "0.0170659549512\n",
      "0.0146493602708\n",
      "0.0170624737991\n",
      "0.014647723804\n",
      "0.0170590084887\n",
      "0.0146460990666\n",
      "0.0170555590059\n",
      "0.0146444860308\n",
      "0.0170521253363\n",
      "0.0146428846689\n",
      "0.0170487074656\n",
      "0.0146412949528\n",
      "0.0170453053793\n",
      "0.0146397168547\n",
      "0.0170419190632\n",
      "0.0146381503465\n",
      "0.0170385485026\n",
      "0.0146365954003\n",
      "0.017035193683\n",
      "0.0146350519879\n",
      "0.0170318545899\n",
      "0.0146335200812\n",
      "0.0170285312086\n",
      "0.0146319996521\n",
      "0.0170252235245\n",
      "0.0146304906722\n",
      "0.017021931523\n",
      "0.0146289931134\n",
      "0.0170186551891\n",
      "0.0146275069473\n",
      "0.0170153945082\n",
      "0.0146260321456\n",
      "0.0170121494654\n",
      "0.0146245686799\n",
      "0.0170089200458\n",
      "0.0146231165218\n",
      "0.0170057062345\n",
      "0.0146216756428\n",
      "0.0170025080165\n",
      "0.0146202460144\n",
      "0.0169993253769\n",
      "0.0146188276081\n",
      "0.0169961583004\n",
      "0.0146174203953\n",
      "0.0169930067721\n",
      "0.0146160243475\n",
      "0.0169898707768\n",
      "0.0146146394359\n",
      "0.0169867502992\n",
      "0.014613265632\n",
      "0.0169836453242\n",
      "0.014611902907\n",
      "0.0169805558365\n",
      "0.0146105512323\n",
      "0.0169774818207\n",
      "0.0146092105791\n",
      "0.0169744232615\n",
      "0.0146078809186\n",
      "0.0169713801434\n",
      "0.0146065622221\n",
      "0.016968352451\n",
      "0.0146052544607\n",
      "0.0169653401688\n",
      "0.0146039576056\n",
      "0.0169623432812\n",
      "0.0146026716279\n",
      "0.0169593617726\n",
      "0.0146013964989\n",
      "0.0169563956275\n",
      "0.0146001321895\n",
      "0.01695344483\n",
      "0.0145988786709\n",
      "0.0169505093645\n",
      "0.0145976359141\n",
      "0.0169475892153\n",
      "0.0145964038902\n",
      "0.0169446843664\n",
      "0.0145951825703\n",
      "0.0169417948021\n",
      "0.0145939719253\n",
      "0.0169389205064\n",
      "0.0145927719264\n",
      "0.0169360614634\n",
      "0.0145915825444\n",
      "0.016933217657\n",
      "0.0145904037504\n",
      "0.0169303890714\n",
      "0.0145892355154\n",
      "0.0169275756902\n",
      "0.0145880778104\n",
      "0.0169247774976\n",
      "0.0145869306063\n",
      "0.0169219944772\n",
      "0.0145857938741\n",
      "0.0169192266128\n",
      "0.0145846675847\n",
      "0.0169164738883\n",
      "0.0145835517092\n",
      "0.0169137362873\n",
      "0.0145824462184\n",
      "0.0169110137934\n",
      "0.0145813510833\n",
      "0.0169083063903\n",
      "0.0145802662749\n",
      "0.0169056140615\n",
      "0.0145791917642\n",
      "0.0169029367905\n",
      "0.014578127522\n",
      "0.0169002745609\n",
      "0.0145770735193\n",
      "0.016897627356\n",
      "0.0145760297271\n",
      "0.0168949951593\n",
      "0.0145749961163\n",
      "0.0168923779541\n",
      "0.014573972658\n",
      "0.0168897757237\n",
      "0.014572959323\n",
      "0.0168871884514\n",
      "0.0145719560824\n",
      "0.0168846161203\n",
      "0.0145709629071\n",
      "0.0168820587137\n",
      "0.0145699797681\n",
      "0.0168795162147\n",
      "0.0145690066365\n",
      "0.0168769886063\n",
      "0.0145680434832\n",
      "0.0168744758717\n",
      "0.0145670902793\n",
      "0.0168719779937\n",
      "0.0145661469958\n",
      "0.0168694949554\n",
      "0.0145652136037\n",
      "0.0168670267396\n",
      "0.0145642900742\n",
      "0.0168645733293\n",
      "0.0145633763782\n",
      "0.0168621347072\n",
      "0.0145624724869\n",
      "0.0168597108562\n",
      "0.0145615783714\n",
      "0.0168573017589\n",
      "0.0145606940029\n",
      "0.0168549073981\n",
      "0.0145598193523\n",
      "0.0168525277564\n",
      "0.0145589543911\n",
      "0.0168501628165\n",
      "0.0145580990902\n",
      "0.0168478125608\n",
      "0.0145572534209\n",
      "0.0168454769719\n",
      "0.0145564173545\n",
      "0.0168431560324\n",
      "0.0145555908622\n",
      "0.0168408497245\n",
      "0.0145547739153\n",
      "0.0168385580308\n",
      "0.014553966485\n",
      "0.0168362809335\n",
      "0.0145531685426\n",
      "0.016834018415\n",
      "0.0145523800596\n",
      "0.0168317704576\n",
      "0.0145516010073\n",
      "0.0168295370434\n",
      "0.0145508313571\n",
      "0.0168273181546\n",
      "0.0145500710804\n",
      "0.0168251137734\n",
      "0.0145493201487\n",
      "0.0168229238819\n",
      "0.0145485785335\n",
      "0.0168207484621\n",
      "0.0145478462062\n",
      "0.016818587496\n",
      "0.0145471231385\n",
      "0.0168164409656\n",
      "0.0145464093019\n",
      "0.0168143088529\n",
      "0.014545704668\n",
      "0.0168121911396\n",
      "0.0145450092084\n",
      "0.0168100878077\n",
      "0.0145443228949\n",
      "0.0168079988389\n",
      "0.0145436456992\n",
      "0.0168059242151\n",
      "0.0145429775929\n",
      "0.0168038639178\n",
      "0.0145423185479\n",
      "0.0168018179288\n",
      "0.0145416685361\n",
      "0.0167997862297\n",
      "0.0145410275292\n",
      "0.0167977688021\n",
      "0.0145403954991\n",
      "0.0167957656276\n",
      "0.0145397724179\n",
      "0.0167937766876\n",
      "0.0145391582574\n",
      "0.0167918019636\n"
     ]
    }
   ],
   "source": [
    "lr.fit(X,Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred = lr.predict(X)\n",
    "accuracy = np.sum(Y == y_pred, axis=0) / len(Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "predict acc 0.96\n"
     ]
    }
   ],
   "source": [
    "print('predict acc %s'%accuracy[0])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
